{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 通过Numpy计算向量内积与对应元素相乘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],\n",
       "       [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],\n",
       "       [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],\n",
       "       [40, 41, 42, 43, 44, 45, 46, 47, 48, 49]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ar1=np.arange(50).reshape(5,10)\n",
    "ar1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [15, 16, 17, 18, 19],\n",
       "       [20, 21, 22, 23, 24],\n",
       "       [25, 26, 27, 28, 29],\n",
       "       [30, 31, 32, 33, 34],\n",
       "       [35, 36, 37, 38, 39],\n",
       "       [40, 41, 42, 43, 44],\n",
       "       [45, 46, 47, 48, 49]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ar2=np.arange(50).reshape(10,5)\n",
    "ar2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "ar3=ar1.T # 转置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0, 10, 20, 30, 40],\n",
       "       [ 1, 11, 21, 31, 41],\n",
       "       [ 2, 12, 22, 32, 42],\n",
       "       [ 3, 13, 23, 33, 43],\n",
       "       [ 4, 14, 24, 34, 44],\n",
       "       [ 5, 15, 25, 35, 45],\n",
       "       [ 6, 16, 26, 36, 46],\n",
       "       [ 7, 17, 27, 37, 47],\n",
       "       [ 8, 18, 28, 38, 48],\n",
       "       [ 9, 19, 29, 39, 49]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ar3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  285,   735,  1185,  1635,  2085],\n",
       "       [  735,  2185,  3635,  5085,  6535],\n",
       "       [ 1185,  3635,  6085,  8535, 10985],\n",
       "       [ 1635,  5085,  8535, 11985, 15435],\n",
       "       [ 2085,  6535, 10985, 15435, 19885]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(ar1,ar3) # 内积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 300,  310,  320,  330,  340,  350,  360,  370,  380,  390],\n",
       "       [ 800,  835,  870,  905,  940,  975, 1010, 1045, 1080, 1115],\n",
       "       [1300, 1360, 1420, 1480, 1540, 1600, 1660, 1720, 1780, 1840],\n",
       "       [1800, 1885, 1970, 2055, 2140, 2225, 2310, 2395, 2480, 2565],\n",
       "       [2300, 2410, 2520, 2630, 2740, 2850, 2960, 3070, 3180, 3290],\n",
       "       [2800, 2935, 3070, 3205, 3340, 3475, 3610, 3745, 3880, 4015],\n",
       "       [3300, 3460, 3620, 3780, 3940, 4100, 4260, 4420, 4580, 4740],\n",
       "       [3800, 3985, 4170, 4355, 4540, 4725, 4910, 5095, 5280, 5465],\n",
       "       [4300, 4510, 4720, 4930, 5140, 5350, 5560, 5770, 5980, 6190],\n",
       "       [4800, 5035, 5270, 5505, 5740, 5975, 6210, 6445, 6680, 6915]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(ar2,ar1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
